/*
 * Helstius--Basic chemistry application
 * This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 * Copyright 2012 Jaked122
 */
package org.helstius.Gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import java.awt.GridBagLayout;
import javax.swing.JTextField;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MolarityGui extends JFrame {

	private JPanel contentPane;
	private JTextField Moles;
	private JTextField Liters;
	JLabel lblMolarity;
	private JTextField Concentration;
	private JTextField txtVolumefield;
	private JTextField Output;

	/**
	 * Create the frame.
	 */
	public MolarityGui() {
		setResizable(false);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));

		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		contentPane.add(tabbedPane, BorderLayout.CENTER);

		JPanel panel = new JPanel();
		tabbedPane.addTab("Moles Known", null, panel, null);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[] { 54, 0, 0 };
		gbl_panel.rowHeights = new int[] { 0, 0, 0, 0 };
		gbl_panel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
		gbl_panel.rowWeights = new double[] { 0.0, 0.0, 1.0, Double.MIN_VALUE };
		panel.setLayout(gbl_panel);

		JLabel lblNumberOfMoles = new JLabel("Number of Moles");
		GridBagConstraints gbc_lblNumberOfMoles = new GridBagConstraints();
		gbc_lblNumberOfMoles.insets = new Insets(0, 0, 5, 5);
		gbc_lblNumberOfMoles.anchor = GridBagConstraints.EAST;
		gbc_lblNumberOfMoles.gridx = 0;
		gbc_lblNumberOfMoles.gridy = 0;
		panel.add(lblNumberOfMoles, gbc_lblNumberOfMoles);

		Moles = new JTextField();
		GridBagConstraints gbc_Moles = new GridBagConstraints();
		gbc_Moles.insets = new Insets(0, 0, 5, 0);
		gbc_Moles.fill = GridBagConstraints.HORIZONTAL;
		gbc_Moles.gridx = 1;
		gbc_Moles.gridy = 0;
		panel.add(Moles, gbc_Moles);
		Moles.setColumns(10);

		JLabel lblLiters = new JLabel("Liters");
		GridBagConstraints gbc_lblLiters = new GridBagConstraints();
		gbc_lblLiters.anchor = GridBagConstraints.EAST;
		gbc_lblLiters.insets = new Insets(0, 0, 5, 5);
		gbc_lblLiters.gridx = 0;
		gbc_lblLiters.gridy = 1;
		panel.add(lblLiters, gbc_lblLiters);

		Liters = new JTextField();
		GridBagConstraints gbc_Liters = new GridBagConstraints();
		gbc_Liters.insets = new Insets(0, 0, 5, 0);
		gbc_Liters.fill = GridBagConstraints.HORIZONTAL;
		gbc_Liters.gridx = 1;
		gbc_Liters.gridy = 1;
		panel.add(Liters, gbc_Liters);
		Liters.setColumns(10);
		lblMolarity = new JLabel("Molarity");
		JButton btnCalculate = new JButton("Calculate");
		btnCalculate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				float i = Float.parseFloat(Liters.getText());
				float m = Float.parseFloat(Moles.getText());
				lblMolarity.setText("Molarity:" + Float.toString(m / i));
			}
		});
		GridBagConstraints gbc_btnCalculate = new GridBagConstraints();
		gbc_btnCalculate.fill = GridBagConstraints.BOTH;
		gbc_btnCalculate.insets = new Insets(0, 0, 0, 5);
		gbc_btnCalculate.gridx = 0;
		gbc_btnCalculate.gridy = 2;
		panel.add(btnCalculate, gbc_btnCalculate);

		GridBagConstraints gbc_lblMolarity = new GridBagConstraints();
		gbc_lblMolarity.gridx = 1;
		gbc_lblMolarity.gridy = 2;
		panel.add(lblMolarity, gbc_lblMolarity);

		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("Moles Unknown", null, panel_1, null);
		GridBagLayout gbl_panel_1 = new GridBagLayout();
		gbl_panel_1.columnWidths = new int[] { 0, 0, 0 };
		gbl_panel_1.rowHeights = new int[] { 0, 0, 0, 0 };
		gbl_panel_1.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
		gbl_panel_1.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
		panel_1.setLayout(gbl_panel_1);

		JLabel lblConcentration = new JLabel("Concentration");
		GridBagConstraints gbc_lblConcentration = new GridBagConstraints();
		gbc_lblConcentration.anchor = GridBagConstraints.EAST;
		gbc_lblConcentration.insets = new Insets(0, 0, 5, 5);
		gbc_lblConcentration.gridx = 0;
		gbc_lblConcentration.gridy = 0;
		panel_1.add(lblConcentration, gbc_lblConcentration);

		Concentration = new JTextField();
		GridBagConstraints gbc_Concentration = new GridBagConstraints();
		gbc_Concentration.insets = new Insets(0, 0, 5, 0);
		gbc_Concentration.fill = GridBagConstraints.HORIZONTAL;
		gbc_Concentration.gridx = 1;
		gbc_Concentration.gridy = 0;
		panel_1.add(Concentration, gbc_Concentration);
		Concentration.setColumns(10);

		JLabel lblVolume = new JLabel("Volume");
		GridBagConstraints gbc_lblVolume = new GridBagConstraints();
		gbc_lblVolume.anchor = GridBagConstraints.EAST;
		gbc_lblVolume.insets = new Insets(0, 0, 5, 5);
		gbc_lblVolume.gridx = 0;
		gbc_lblVolume.gridy = 1;
		panel_1.add(lblVolume, gbc_lblVolume);

		JButton btnNewButton = new JButton("Calculate");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				float c = Float.parseFloat(Concentration.getText());
				float v = Float.parseFloat(txtVolumefield.getText());
				Output.setText(Float.toString(v * c));
			}
		});

		txtVolumefield = new JTextField();
		GridBagConstraints gbc_txtVolumefield = new GridBagConstraints();
		gbc_txtVolumefield.insets = new Insets(0, 0, 5, 0);
		gbc_txtVolumefield.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtVolumefield.gridx = 1;
		gbc_txtVolumefield.gridy = 1;
		panel_1.add(txtVolumefield, gbc_txtVolumefield);
		txtVolumefield.setColumns(10);
		GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
		gbc_btnNewButton.insets = new Insets(0, 0, 0, 5);
		gbc_btnNewButton.gridx = 0;
		gbc_btnNewButton.gridy = 2;
		panel_1.add(btnNewButton, gbc_btnNewButton);

		Output = new JTextField();
		Output.setEditable(false);
		GridBagConstraints gbc_Output = new GridBagConstraints();
		gbc_Output.fill = GridBagConstraints.HORIZONTAL;
		gbc_Output.gridx = 1;
		gbc_Output.gridy = 2;
		panel_1.add(Output, gbc_Output);
		Output.setColumns(10);
	}

}
